package com.zxy.leetcode._00000_00099._00000_00009;

/**
 * https://leetcode-cn.com/problems/reverse-integer/
 */
public class Test00007 {

    public static void main(String[] args) {
        System.out.println(new Test00007().reverse(1534236469));
        System.out.println(new Test00007().reverse(200));
        System.out.println(new Test00007().reverse(-201));
    }

    public int reverse(int x) {
        long a = 0;
        int b = 0;
        while (x != 0) {
            a = a * 10 + (x % 10);
            x = x / 10;
            b = (int)a;

            // 题目要求溢出要返回0，这里拿来判断是否溢出了
            if (a != b) {
                return 0;
            }
        }

        return b;
    }

}
